package com.example.yls.demoa;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button btnSendBroad;
    private Button btnSendLocal;
    private HighReceiver hReceiver;
    private MidReceiver mReceiver;
    private LowReceiver lReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        IntentFilter hfilter = new IntentFilter();
        hfilter.setPriority(100);
        hReceiver = new HighReceiver();
        registerReceiver(hReceiver,hfilter);

        IntentFilter mfilter = new IntentFilter();
        mfilter.setPriority(50);
        mReceiver = new MidReceiver();
        registerReceiver(mReceiver,mfilter);

        IntentFilter lfilter = new IntentFilter();
        lfilter.setPriority(0);
        lReceiver = new LowReceiver();
        registerReceiver(lReceiver,lfilter);


        btnSendBroad = findViewById(R.id.btn_sendBroad);
        btnSendBroad.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent =new Intent();
                intent.setAction("weather_report");
                sendOrderedBroadcast(intent,null);
            }
        });


        btnSendLocal = findViewById(R.id.btn_sendLocal);
        btnSendLocal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LocalBroadcastManager manager
                        = LocalBroadcastManager.getInstance();
            }
        });

    }
}

















